 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
In
C++, the new and delete operators provide
|
|
 |
|
|
|
|
build-in
language support for dynamic memory
|
|
|
allocation and
deallocation.
|
|
|
|
This
feature has several benefits:
|
|
 |
|
|
|
|
|
n |
Reduces
common programmer errors: it is
easy to
|
|
|
forget to
multiply the number of objects being
|
|
|
allocated by
sizeof when using malloc.
|
|
|
|
n |
Enhances
source code clarity: generally,
there is no
|
|
|
need to: (1)
declare operator new and delete, (2)
|
|
|
explicitly use
casts, or (3) explicitly check the return
|
|
|
value.
|
|
|
|
n |
Improves
run-time efficiency: (1) users can
redefine
|
|
|
operator new and delete globally and
also define then
|
|
on a per-class
basis and (2) calls can be inlined.
|
|